/**
 * [后台菜单管理]列表首页[JS]
 * @returns {*}
 */
var app = function () {
    Vue.component('treeselect', VueTreeselect.Treeselect);
    return new Vue({
        el: '#vueContainer',
        data: {
            loadOver: false,
            setting: {
                status: {
                    disabled: -1,
                    open: 1,
                },
                statusTxt: {
                    '-1': '禁用',
                    1: '开启',
                },
                showAllSearch: false,  // 展示全部查询
                dialogVis: false,
                clearVis: false, // 清除缓存弹出层
                isAdd: false, // 是否添加数据
                treeRightHover: false, // 数级菜单是否移入
                showClearConfirm: true, // 是否展示信息清除缓存改变弹出层
                sortMax: 9999999, // 排序允许最大
                sortMin: -999999, // 排序允许最小
            },
            baseDiaTitle: '', // 弹出层基础标题
            dataList: [], // 父级数据列表
            addDataList: [], // 添加修改数据
            handelSelectList: [], // 当前多选项
            page: 1,
            page_size: 20,
            dataTotal: 0,
            addForm: {},
            addFormRules: {
                name: [
                    {required: true, message: '请填写名称', trigger: 'blur'}
                ],
                parent_id: [
                    {required: true, message: '请选择上级分类', trigger: 'blur'}
                ],
                status: [
                    {required: true, message: '请选择状态', trigger: 'blur'}
                ],
                url: [
                    {required: true, message: '请填写菜单连接', trigger: 'blur'}
                ],
            },
            searchForm: {},
            clearRoleInfo: {
                loading: false, // 正在加载
                loadingTxt: '加载中...', // 正在加载
                roleForm: {
                    status: 1, // 状态为正常
                    name: null
                }, // 自定义错误信息
                dataList: [], // 角色列表
                idList: [], // 所选择角色编号列表
                page: 1,
                pageSize: 20,
                dataTotal: 0,
                loadAllOver: false, // 已全部加载完毕
                isIndeterminate: false, // 全选是否半全选
                checkAll: false, // 是否全选
                maxChecked: 10 // 最多选择数量
            }, // 即将要清除的所选角色编号列表
            filterText: '',
            customErrMsg: {}, // 自定义错误信息,
            clearCache: {
                showClearDialog: false, // 清除缓存弹出层
                showClearLoading: false, // 清除缓存弹出层正在加载
                pageUrl: '', // 清除缓存连接
            }, // 清除缓存内容
        },
        created: function () {
            // 获取下列表
            this.getList(false);
            var that = this;
            this.$nextTick(function () {
                that.loadOver = true;
            });
        },
        methods: {
            /**
             * 初始化添加、修改[表单]
             */
            initAddForm: function () {
                this.addForm = {
                    name: null,
                    parent_id: null,
                    sort: 0,
                    status: 1,
                    url: null,
                    font_icon: null
                };
            },
            /**
             * 获取下列表
             */
            getList: function ($noLoading) {

                $noLoading = $noLoading || false;

                // 正在加载...
                if (!$noLoading) var loadingInstance = ELEMENT.Loading.service({
                    fullscreen: false,
                    text: '加载中...'
                });
                var that = this;

                // 获取各模块的值
                $.ajax({
                    url: $w.getApiUrl('adminMenu.list'),
                    type: 'get',
                    data: {
                        page: this.page,
                        page_size: this.page_size
                    },
                    dataType: "json",
                    success: function (event) {

                        that.$nextTick(function () {

                            // 隐藏正在加载
                            if (!$noLoading) loadingInstance.close();
                        });

                        // 必须先登录
                        if (parseInt(event.no) === 403) {

                            that.$message({
                                type: 'warning',
                                showClose: true,
                                message: '登陆超时，请重新登陆'
                            });

                            // 几秒之后移除
                            return setTimeout(function () {
                                window.parent.location.href = $w.getPageUrl('login');
                            }, 810);
                        }

                        // 操作失败显示错误信息
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                type: 'error',
                                showClose: true,
                                message: event.msg
                            });
                        }

                        // 数据
                        that.dataList = event.data.list;

                        // 总条目
                        that.dataTotal = parseInt(event.data.total);
                        // 复制下添加数据列表
                        that.addDataList = [
                            {
                                id: 0,
                                label: '作为顶部菜单',
                                parent_id: false
                            }
                        ];
                        Array.prototype.push.apply(that.addDataList, that.dataList);
                    },
                    error: function () {

                        // 按钮正在加载
                        if (!$noLoading) loadingInstance.close();
                        return that.$message({
                            type: 'error',
                            showClose: true,
                            message: '操作频繁，请稍后尝试'
                        });
                    }
                });
            },
            /**
             * 恢复记录
             */
            openItem: function ($id) {

                // 如果 $id 不传值 就 走列表
                if (!$id || $id.length <= 0) {
                    $id = this.handelSelectList;
                }

                // 判断id是否为空
                if (!$id || $id.length <= 0) {
                    return this.$message({
                        showClose: true,
                        type: 'error',
                        message: '请至少选择一个条目'
                    });
                }

                var that = this;

                this.$confirm('此操作将【开启】数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '正在开启...'
                    });

                    // 获取各模块的值
                    $.ajax({
                        url: $w.getApiUrl('adminMenu.open'),
                        type: 'POST',
                        data: {idList: $id},
                        dataType: "json",
                        success: function (event) {

                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            // 必须先登录
                            if (parseInt(event.no) === 403) {

                                that.$message({
                                    type: 'warning',
                                    showClose: true,
                                    message: '登陆超时，请重新登陆'
                                });

                                // 几秒之后移除
                                return setTimeout(function () {
                                    window.parent.location.href = $w.getPageUrl('login');
                                }, 810);
                            }

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg
                                });
                            }

                            // 放空列表
                            that.handelSelectList = null;
                            // 成功 加载下列表
                            return that.$nextTick(function () {

                                that.getList(false);
                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        },
                        error: function () {

                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: '请求用频繁稍后尝试'
                            });
                        }
                    });
                });
            },
            /**
             * 禁用记录
             */
            disabledItem: function ($id) {

                // 如果 $id 不传值 就 走列表
                if (!$id || $id.length <= 0) {
                    $id = this.handelSelectList;
                }

                // 判断id是否为空
                if (!$id || $id.length <= 0) {
                    return this.$message({
                        showClose: true,
                        type: 'error',
                        message: '请至少选择一个条目'
                    });
                }

                var that = this;

                this.$confirm('此操作将【禁用】数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '禁用中...'
                    });

                    // 获取各模块的值
                    $.ajax({
                        url: $w.getApiUrl('adminMenu.disabled'),
                        type: 'POST',
                        data: {idList: $id},
                        dataType: "json",
                        success: function (event) {

                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            // 必须先登录
                            if (parseInt(event.no) === 403) {

                                that.$message({
                                    type: 'warning',
                                    showClose: true,
                                    message: '登陆超时，请重新登陆'
                                });

                                // 几秒之后移除
                                return setTimeout(function () {
                                    window.parent.location.href = $w.getPageUrl('login');
                                }, 810);
                            }

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg
                                });
                            }

                            // 放空列表
                            that.handelSelectList = null;
                            // 成功 加载下列表
                            return that.$nextTick(function () {

                                that.getList(false);
                                // 提示是否调用刷新缓存

                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        },
                        error: function () {

                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: '请求用频繁稍后尝试'
                            });
                        }
                    });
                });
            },
            /**
             * 排序
             * @param $sortData
             * @returns {*}
             */
            sortItem: function ($sortData) {

                if (!$sortData || $sortData.length < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '暂无子集，无法排序'
                    });
                }

                var loadingInstance = ELEMENT.Loading.service({
                    fullscreen: false,
                    text: '提交中...'
                });
                var that = this;
                $.ajax({
                    url: $w.getApiUrl('adminMenu.sort'),
                    type: 'POST',
                    data: {sortData: $sortData},
                    dataType: "json",
                    success: function (event) {

                        that.$nextTick(function () {
                            // 隐藏正在加载
                            loadingInstance.close();
                        });
                        // 必须先登录
                        if (parseInt(event.no) === 403) {

                            that.$message({
                                type: 'warning',
                                showClose: true,
                                message: '登陆超时，请重新登陆'
                            });

                            // 几秒之后移除
                            return setTimeout(function () {
                                window.parent.location.href = $w.getPageUrl('login');
                            }, 810);
                        }

                        // 操作失败显示错误信息
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                type: 'error',
                                showClose: true,
                                message: event.msg
                            });
                        }

                        // 提示是否调用刷新缓存
                        return true;
                    },
                    error: function (event) {

                        that.$nextTick(function () {
                            // 隐藏正在加载
                            loadingInstance.close();
                        });
                        return that.$message({
                            type: 'error',
                            showClose: true,
                            message: '操作频繁，请稍后尝试'
                        });
                    }
                });
            },
            /**
             * 提交添加
             */
            submitAdd: function () {

                var that = this;

                // 清空错误信息
                this.$set(that, 'customErrMsg', {});
                this.$refs['addForm'].validate(function (valid, msg) {

                    // 验证不过
                    if (!valid) return false;

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '添加中...'
                    });

                    // 是否越出范围值 大于
                    if (parseInt(that.addForm.sort) > that.setting.sortMax) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最大不得超过 ' + that.setting.sortMax
                        });

                        return loadingInstance.close();
                    }

                    // 是否越出范围值 小于
                    if (parseInt(that.addForm.sort) < that.setting.sortMin) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最小不得小于 ' + that.setting.sortMin
                        });

                        return loadingInstance.close();
                    }

                    $.ajax({
                        url: $w.getApiUrl('adminMenu.create'),
                        type: 'POST',
                        data: that.addForm,
                        dataType: "json",
                        success: function (event) {

                            that.$nextTick(function () {

                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            // 必须先登录
                            if (parseInt(event.no) === 403) {

                                that.$message({
                                    type: 'warning',
                                    showClose: true,
                                    message: '登陆超时，请重新登陆'
                                });

                                // 几秒之后移除
                                return setTimeout(function () {
                                    window.parent.location.href = $w.getPageUrl('login');
                                }, 810);
                            }

                            // 操作失败显示错误信息
                            if (parseInt(event.no) !== 200) {

                                for (var i in event.data.columnError) {
                                    if (!event.data.columnError.hasOwnProperty(i)) continue;
                                    that.$set(that.customErrMsg, i, event.data.columnError[i]);
                                }
                                return that.$message({
                                    type: 'error',
                                    showClose: true,
                                    message: event.msg
                                });
                            }

                            that.setting.dialogVis = false;
                            return that.$nextTick(function () {
                                that.getList(false);
                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        },
                        error: function (event) {

                            // 按钮正在加载
                            that.$nextTick(function () {

                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                            return that.$message({
                                type: 'error',
                                showClose: true,
                                message: '操作频繁，请稍后尝试'
                            });
                        }
                    });
                });
            },
            /**
             * 提交修改
             * @param $ref
             * @returns {boolean}
             */
            submitUpdate: function ($ref) {

                if (!$w.in_array($ref, ['addForm', ['stageForm']])) {
                    this.$message({
                        showClose: true,
                        type: 'error',
                        message: '更新失败'
                    });
                    console.error('更新方法参数`$ref`非法：' + $ref);
                    return false;
                }
                var that = this;

                // 清空错误信息
                this.$set(that, 'customErrMsg', {});
                this.$refs[$ref].validate(function (valid, msg) {

                    // 验证不过
                    if (!valid) return false;

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '更新中...',
                        customClass: 'z-index-top'
                    });

                    // 是否越出范围值 大于
                    if (parseInt(that.addForm.sort) > that.setting.sortMax) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最大不得超过 ' + that.setting.sortMax
                        });

                        return loadingInstance.close();
                    }

                    // 是否越出范围值 小于
                    if (parseInt(that.addForm.sort) < that.setting.sortMin) {

                        that.$message({
                            showClose: true,
                            type: 'error',
                            message: '排序最小不得小于 ' + that.setting.sortMin
                        });

                        return loadingInstance.close();
                    }

                    $.ajax({
                        url: $w.getApiUrl('adminMenu.update'),
                        type: 'POST',
                        data: that.addForm,
                        dataType: "json",
                        success: function (event) {

                            that.$nextTick(function () {

                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            // 必须先登录
                            if (parseInt(event.no) === 403) {

                                that.$message({
                                    type: 'warning',
                                    showClose: true,
                                    message: '登陆超时，请重新登陆'
                                });

                                // 几秒之后移除
                                return setTimeout(function () {
                                    window.parent.location.href = $w.getPageUrl('login');
                                }, 810);
                            }

                            // 操作失败显示错误信息
                            if (parseInt(event.no) !== 200) {

                                for (var i in event.data.columnError) {
                                    if (!event.data.columnError.hasOwnProperty(i)) continue;
                                    that.$set(that.customErrMsg, i, event.data.columnError[i]);
                                }
                                return that.$message({
                                    type: 'error',
                                    showClose: true,
                                    message: event.msg
                                });
                            }

                            that.setting.dialogVis = false;
                            return that.$nextTick(function () {
                                that.getList(true);
                                // 提示是否调用刷新缓存
                                that.dataChange();
                            });
                        },
                        error: function (event) {

                            // 按钮正在加载
                            that.$nextTick(function () {

                                // 隐藏正在加载
                                loadingInstance.close();
                            });
                            return that.$message({
                                type: 'error',
                                showClose: true,
                                message: '操作频繁，请稍后尝试'
                            });
                        }
                    });
                });
            },
            /**
             * [更多查询]按钮点击
             */
            moreSearchClick: function () {
                if (this.setting.showAllSearch) {
                    this.setting.showAllSearch = false;
                    return true;
                }
                this.setting.showAllSearch = true;

            },
            /**
             * 过滤是否展示节点
             */
            filterNode: function ($value, $data) {
                if (!$value) return true;
                return $data.label.indexOf($value) !== -1;
            },
            /**
             * 跳转到添加
             */
            goToCreate: function ($id, $node) {

                // 检测级别
                if ($node && parseInt($node['level']) === 3) {

                    return this.$message({
                        showClose: true,
                        type: 'warning',
                        message: '三级菜单下无法再添加子集：因为无法展示。'
                    });
                }

                // 先初始化添加表单
                this.initAddForm();
                // [$id]存在，赋值
                if ($id && $id.length > 0) this.addForm.parent_id = $id;
                // 操作弹出框标题
                this.baseDiaTitle = '添加';
                // 表示正在添加
                this.setting.isAdd = true;
                // 展示弹出
                this.setting.dialogVis = true;
                // 获取列表
                this.getList(true);
            },
            /**
             * 跳转到编辑
             */
            goToUpdate: function ($id) {

                // 判断id是否为空
                if (!$id || $id.length <= 0) {
                    return this.$message({
                        showClose: true,
                        type: 'warning',
                        message: '请至少选择一个条目'
                    });
                }

                var that = this;

                // 正在加载。。
                var loadingInstance = ELEMENT.Loading.service([]);

                // 获取各模块的值
                $.ajax({
                    url: $w.getApiUrl('adminMenu.detail'),
                    type: 'GET',
                    data: {id: $id},
                    dataType: "json",
                    success: function (event) {

                        that.$nextTick(function () {
                            // 隐藏正在加载
                            loadingInstance.close();
                        });

                        // 必须先登录
                        if (parseInt(event.no) === 403) {

                            that.$message({
                                type: 'warning',
                                showClose: true,
                                message: '登陆超时，请重新登陆'
                            });

                            // 几秒之后移除
                            return setTimeout(function () {
                                window.parent.location.href = $w.getPageUrl('login');
                            }, 810);
                        }

                        // 失败的返回|提示
                        if (parseInt(event.no) !== 200) {

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: event.msg
                            });
                        }

                        // 放空列表
                        that.addForm = event.data;
                        // 成功 加载下列表
                        return that.$nextTick(function () {

                            this.baseDiaTitle = '修改';
                            this.setting.isAdd = false;
                            this.setting.dialogVis = true;
                        });
                    },
                    error: function () {

                        that.$nextTick(function () {
                            // 隐藏正在加载
                            loadingInstance.close();
                        });

                        return that.$message({
                            showClose: true,
                            type: 'error',
                            message: '请求用频繁稍后尝试'
                        });
                    }
                });
            },
            /**
             * 检测树菜单点选
             * @param $data
             * @param $checked
             * @param $indeterminate
             */
            handleTreeCheck: function ($data, $checked, $indeterminate) {

                // 初始化下
                if (!this.handelSelectList || this.handelSelectList.length < 1) {
                    this.handelSelectList = [];
                }

                // 选中
                if ($checked) {
                    this.handelSelectList.push($data['id']);
                } else {
                    var item;
                    for (var i in this.handelSelectList) {
                        if (!this.handelSelectList.hasOwnProperty(i)) continue;
                        item = this.handelSelectList[i];
                        if (item['id'] === $data['id']) {
                            delete this.handelSelectList[i];
                        }
                    }
                }
            },
            /**
             * 监测拖拽完成
             */
            handelNodeDrop: function ($draggingNode, $dropNode, $dropType, $ev) {

                // 默认先赋值移动的数据
                this.addForm = $draggingNode['data'];

                // 加入到某节点之前
                if ($dropType === 'before') {

                    // 当前[父级编号] 为被捉拽对象的父级编号
                    this.addForm['parent_id'] = $dropNode['data']['parent_id'];
                    // 排序大于当节点排序
                    this.addForm['sort'] = parseInt($dropNode['data']['sort']) + 1;
                } else if ($dropType === 'after') { // 之后

                    // 当前[父级编号] 为被捉拽对象的父级编号
                    this.addForm['parent_id'] = $dropNode['data']['parent_id'];
                    // 排序小于当节点排序
                    this.addForm['sort'] = parseInt($dropNode['data']['sort']) - 1;
                } else if ($dropType === 'inner') { // 加入到某节点之下

                    // 当前[父级编号] 为被捉拽对象的父级编号
                    this.addForm['parent_id'] = $dropNode['data']['id'];
                    // 循环格式化排序
                    var sort = 1;
                    var children = $dropNode['data']['children'];
                    for (var i in children) {
                        if (!children.hasOwnProperty(i)) continue;

                        // 判断编号如果和正在 更新的一样
                        if (parseInt(children[i]['sort']) < sort) {
                            // 排序值赋值
                            sort = children[i]['sort'];
                        }
                    }
                    // 排序小于当节点排序
                    this.addForm['sort'] = parseInt(sort) - 1;
                }

                // 执行下更新
                this.submitUpdate('stageForm');
            },
            /**
             * 实时监测菜单是否可放置
             * @param $draggingNode
             * @param $dropNode
             * @param $dropType
             * @returns {boolean}
             */
            treeAllowDrop: function ($draggingNode, $dropNode, $dropType) {

                // 加入到某节点之前
                if ($dropType === 'prev' && $dropNode.level > 3) {

                    return false
                } else if ($dropType === 'next' && $dropNode.level > 3) { // 之后

                    return false;
                } else if ($dropType === 'inner' && $dropNode.level >= 3) { // 加入到某节点之下

                    return false;
                }
                return true;
            },
            /**
             * 提交渲染菜单
             */
            renderMenu: function () {

                var that = this;

                this.$confirm('确定要渲染菜单吗, 渲染后后台将展示最新菜单, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {

                    // 正在加载。。
                    var loadingInstance = ELEMENT.Loading.service({
                        fullscreen: false,
                        text: '渲染中...'
                    });

                    // 获取各模块的值
                    $.ajax({
                        url: $w.getApiUrl('adminMenu.render'),
                        type: 'POST',
                        data: {},
                        dataType: "json",
                        success: function (event) {

                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            // 必须先登录
                            if (parseInt(event.no) === 403) {

                                that.$message({
                                    type: 'warning',
                                    showClose: true,
                                    message: '登陆超时，请重新登陆'
                                });

                                // 几秒之后移除
                                return setTimeout(function () {
                                    window.parent.location.href = $w.getPageUrl('login');
                                }, 810);
                            }

                            // 失败的返回|提示
                            if (parseInt(event.no) !== 200) {

                                return that.$message({
                                    showClose: true,
                                    type: 'error',
                                    message: event.msg
                                });
                            }

                            // 成功 加载下列表
                            return true;
                        },
                        error: function () {

                            that.$nextTick(function () {
                                // 隐藏正在加载
                                loadingInstance.close();
                            });

                            return that.$message({
                                showClose: true,
                                type: 'error',
                                message: '请求用频繁稍后尝试'
                            });
                        }
                    });
                });
            },
            /**
             * 刷新菜单缓存
             */
            clearRoleCache: function () {

                // 检测编号列表是否超过最大数目
                var max = this.clearRoleInfo.maxChecked;
                if (max < this.clearRoleInfo.idList.length) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '选择角色数量超过' + max + '个'
                    });
                }
                // 检测编号列表是否一个没有
                if (this.clearRoleInfo.idList.length < 1) {
                    return this.$message({
                        type: 'error',
                        showClose: true,
                        message: '请选择一个角色'
                    });
                }

                var that = this;

                // 正在加载
                this.clearRoleInfo.loading = true;
                this.clearRoleInfo.loadingText = '刷新中...';

                // 获取各模块的值
                $.ajax({
                    url: $w.getApiUrl('adminRole.clearCache'),
                    type: 'POST',
                    data: {idList: this.clearRoleInfo.idList},
                    dataType: "json",
                    success: function (event) {

                        that.$nextTick(function () {
                            // 隐藏正在加载
                            that.clearRoleInfo.loading = false;
                        });

                        // 必须先登录
                        if (parseInt(event.no) === 403) {

                            that.$message({
                                type: 'warning',
                                showClose: true,
                                message: '登陆超时，请重新登陆'
                            });

                            // 几秒之后移除
                            return setTimeout(function () {
                                window.parent.location.href = $w.getPageUrl('login');
                            }, 810);
                        }

                        var msgType = 'success';
                        // 失败的返回|提示
                        if (parseInt(event.no) < 200 || parseInt(event.no) > 300)
                            msgType = 'error';
                        else if (parseInt(event.no) === 206)
                            msgType = 'warning';

                        // 成功 加载下列表
                        return that.$message({
                            showClose: true,
                            type: msgType,
                            message: event.msg
                        });
                    },
                    error: function () {

                        that.$nextTick(function () {
                            // 隐藏正在加载
                            that.clearRoleInfo.loading = false;
                        });

                        return that.$message({
                            showClose: true,
                            type: 'error',
                            message: '请求用频繁稍后尝试'
                        });
                    }
                });
            },
            /**
             * 清除缓存 - 展示清除角色缓存弹出层
             */
            showClearDialog: function ($isNewLoad) {

                // 连接赋值
                var cacheList = $w.getApiUrl('clearCache.adminMenu');
                this.clearCache.pageUrl = $w.getPageUrl('clearCache') + '?cacheUrl' + cacheList;

                // 加载中...展示
                this.clearCache.showClearLoading = true;
                // 打开弹出层
                this.clearCache.showClearDialog = true;
                var that = this;
                this.$nextTick(function () {
                    var iframe = that.$refs['cacheIframe'];
                    iframe.onload = function(){
                        // 加载中...隐藏
                        that.clearCache.showClearLoading = false;
                    };
                });
            },
            /**
             * 监测选择全部角色
             */
            handleCheckAllRole: function ($val) {

                // 进行取消全选
                if (!$val) {
                    this.clearRoleInfo.isIndeterminate = false;
                    return this.clearRoleInfo.idList = [];
                }

                var item = [];
                for (var i in this.clearRoleInfo.dataList) {
                    if (!this.clearRoleInfo.dataList.hasOwnProperty(i)) continue;
                    item = this.clearRoleInfo.dataList[i];
                    if (!item.hasOwnProperty('id')) continue;
                    this.clearRoleInfo.idList.push(item['id']);
                }

                return true;
            },
            /**
             * 监测角色一个选择变化
             */
            handleCheckedRole: function ($value) {
                var checkedCount = $value.length;
                var nowListLength = this.clearRoleInfo.dataList.length;
                this.clearRoleInfo.checkAll = checkedCount === nowListLength;
                this.clearRoleInfo.isIndeterminate = checkedCount > 0 && checkedCount < nowListLength;
            },
            /**
             * 角色选择下规定条目数量的数据
             */
            checkRoleNext: function () {
                // 现在所选择数据列表
                var checkedList = this.clearRoleInfo.idList;
                // 从第几个开始，默认第一个，，，
                var startId = false;
                if (checkedList && checkedList.length > 0) {
                    startId = $w.array_end(checkedList);
                }

                var max = this.clearRoleInfo.maxChecked,
                    item, endItem = [], x = 0, open = false;
                // 循环可选择条目
                for (var i in this.clearRoleInfo.dataList) {
                    if (!this.clearRoleInfo.dataList.hasOwnProperty(i)) continue;
                    item = this.clearRoleInfo.dataList[i];
                    // 大于当前条目阈值不操作循环
                    if (x >= max) break;
                    // 如果是开始条目则开启
                    if (startId === false || open === true) {
                        endItem.push(item['id']);
                        x++;
                    }
                    // 可以开始记录了
                    if (startId === false || item['id'] === startId) open = true;
                }

                // 直接赋值
                this.$set(this.clearRoleInfo, 'idList', endItem);
            },
            /**
             * 监测 当列表数据改变
             */
            dataChange: function () {
                // 提示被关闭不提示
                if (!this.setting.showClearConfirm) {
                    return false;
                }
                var that = this;
                // 提示是否调用刷新缓存
                this.$confirm('您已改变菜单数据刷新缓存后才会生效，是否选择角色刷新？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '本次操作不再提示',
                    type: 'warning',
                    dangerouslyUseHTMLString: true,
                    distinguishCancelAndClose: true
                }).then(function () {
                    that.showClearDialog(true);
                }).catch(function ($action) {
                    if ($action === 'cancel') {
                        that.setting.showClearConfirm = false;
                    }
                });
            }
        },
        watch: {
            /**
             * 监测文本过滤
             * @param $val
             */
            'searchForm.label': function ($val) {
                this.$refs.tree.filter($val);
            }
        }
    });
};
